package com.cy.java;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * Collection接口中声明的方法的测试
 */
public class CollectionTest {

    @Test
    public void test1(){
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new String("Tom"));
        coll.add(false);
        coll.add(new Person("Jerry",20));
        //contains(Object obj) 判断当前集合是否包含obj；
        boolean contains = coll.contains(123);
        System.out.println(contains);
        System.out.println(coll.contains(new String("Tom")));;

    }

    @Test
    public void test2(){
        //3.remove(Object obj)从当前集合中移除obj元素
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new String("Tom"));
        coll.add(false);
        coll.add(new Person("Jerry",20));

        coll.remove(123);
        System.out.println(coll);

        //removeAll(Collection coll1)从当前集合中移除coll所有的元素
        Collection coll1 = Arrays.asList(123,4567);
        coll.remove(coll1);
        System.out.println(coll);
    }
}
